DAY9:Friend or Foe?


Posted by birdbirdmurmur on 2023-07-22

題目連結:

Friend or Foe?

解法:

function friend(friends){
  const friend = friends.filter(name => name.length === 4);
  return friend;
}

筆記:

解題時用的變數名稱好像不太好XD
看到別人直接return friends.filter
這樣可以更簡潔一點
我後面使用箭頭函數也方便了很多
玩陣列的其中一個方法filter
filter可以做一次快篩
並直接取代原本的陣列
這樣可以少設一個空陣列


#javascript #Codewars #filter







Related Posts

TypeScript 函式定義字串型別相連和JavaScript String.prototype.concat() 的差異

TypeScript 函式定義字串型別相連和JavaScript String.prototype.concat() 的差異

筆記、09801 計算機網路概論-第1-C講 Computer Networks and the Internet

筆記、09801 計算機網路概論-第1-C講 Computer Networks and the Internet

資訊安全概念

資訊安全概念


Comments